package P287.P141;

/**
 * @Author DJ同学
 * @Date 2021/2/23 8:48
 * @Version 1.0
 * @Name 环形链表
 * @Problem https://leetcode-cn.com/problems/linked-list-cycle/
 * @Idea 注意题目中的pos一点用处都没有 快慢指针
 * 参考：https://www.bilibili.com/video/BV1cQ4y1P7Vd?t=392
 */
public class Solution {
    public boolean hasCycle(ListNode head) {

        if(head==null||head.next==null)return false;
        ListNode fast = head;//走两步
        ListNode slow = head;//走一步
        while(fast!=null&&fast.next!=null){
            fast = fast.next.next;
            slow = slow.next;
            if(fast==slow){
                return true;
            }
        }
        return false;
    }
}
